package com.facebook.imagepipeline.producers;

import android.os.Build.VERSION;
import com.facebook.common.internal.Closeables;
import com.facebook.common.internal.Supplier;
import com.facebook.common.references.CloseableReference;
import com.facebook.imagepipeline.image.EncodedImage;
import com.facebook.imagepipeline.memory.PooledByteBufferFactory;
import com.facebook.imagepipeline.request.ImageRequest;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.concurrent.Executor;

public abstract class LocalFetchProducer
  implements Producer<EncodedImage>
{
  private final boolean mDecodeFileDescriptorEnabledForKitKat;
  private final Executor mExecutor;
  private final PooledByteBufferFactory mPooledByteBufferFactory;

  protected LocalFetchProducer(Executor paramExecutor, PooledByteBufferFactory paramPooledByteBufferFactory, boolean paramBoolean)
  {
    this.mExecutor = paramExecutor;
    this.mPooledByteBufferFactory = paramPooledByteBufferFactory;
    if ((paramBoolean) && (Build.VERSION.SDK_INT == 19));
    for (boolean bool = true; ; bool = false)
    {
      this.mDecodeFileDescriptorEnabledForKitKat = bool;
      return;
    }
  }

  protected EncodedImage getByteBufferBackedEncodedImage(InputStream paramInputStream, int paramInt)
    throws IOException
  {
    Object localObject1 = null;
    if (paramInt <= 0);
    try
    {
      CloseableReference localCloseableReference;
      for (localObject1 = CloseableReference.of(this.mPooledByteBufferFactory.newByteBuffer(paramInputStream)); ; localObject1 = localCloseableReference)
      {
        EncodedImage localEncodedImage = new EncodedImage((CloseableReference)localObject1);
        return localEncodedImage;
        localCloseableReference = CloseableReference.of(this.mPooledByteBufferFactory.newByteBuffer(paramInputStream, paramInt));
      }
    }
    finally
    {
      Closeables.closeQuietly(paramInputStream);
      CloseableReference.closeSafely((CloseableReference)localObject1);
    }
  }

  protected abstract EncodedImage getEncodedImage(ImageRequest paramImageRequest)
    throws IOException;

  protected EncodedImage getEncodedImage(InputStream paramInputStream, int paramInt)
    throws IOException
  {
    Runtime localRuntime = Runtime.getRuntime();
    long l1 = localRuntime.maxMemory();
    long l2 = Math.min(l1 - (localRuntime.totalMemory() - localRuntime.freeMemory()), 8388608L);
    if ((this.mDecodeFileDescriptorEnabledForKitKat) && ((paramInputStream instanceof FileInputStream)) && (l1 >= 64L * l2))
      return getInputStreamBackedEncodedImage(new File(paramInputStream.toString()), paramInt);
    return getByteBufferBackedEncodedImage(paramInputStream, paramInt);
  }

  protected EncodedImage getInputStreamBackedEncodedImage(final File paramFile, int paramInt)
    throws IOException
  {
    return new EncodedImage(new Supplier()
    {
      public FileInputStream get()
      {
        try
        {
          FileInputStream localFileInputStream = new FileInputStream(paramFile);
          return localFileInputStream;
        }
        catch (IOException localIOException)
        {
          throw new RuntimeException(localIOException);
        }
      }
    }
    , paramInt);
  }

  protected abstract String getProducerName();

  public void produceResults(Consumer<EncodedImage> paramConsumer, ProducerContext paramProducerContext)
  {
    ProducerListener localProducerListener = paramProducerContext.getListener();
    String str = paramProducerContext.getId();
    final ImageRequest localImageRequest = paramProducerContext.getImageRequest();
    final StatefulProducerRunnable local1 = new StatefulProducerRunnable(paramConsumer, localProducerListener, getProducerName(), str)
    {
      protected void disposeResult(EncodedImage paramAnonymousEncodedImage)
      {
        EncodedImage.closeSafely(paramAnonymousEncodedImage);
      }

      protected EncodedImage getResult()
        throws Exception
      {
        EncodedImage localEncodedImage = LocalFetchProducer.this.getEncodedImage(localImageRequest);
        if (localEncodedImage == null)
          return null;
        localEncodedImage.parseMetaData();
        return localEncodedImage;
      }
    };
    paramProducerContext.addCallbacks(new BaseProducerContextCallbacks()
    {
      public void onCancellationRequested()
      {
        local1.cancel();
      }
    });
    this.mExecutor.execute(local1);
  }
}

/* Location:           C:\Users\user\Desktop\dd28_pcdd720\classes_dex2jar.jar
 * Qualified Name:     com.facebook.imagepipeline.producers.LocalFetchProducer
 * JD-Core Version:    0.6.2
 */